package com.slliver.service;


import com.slliver.mapper.ProductMapper;
import com.slliver.pojo.Order;
import com.slliver.pojo.Product;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service("productService")
public class ProductService {

    private final ProductMapper productMapper;
    private final RestTemplate restTemplate;

    public ProductService(ProductMapper productMapper,RestTemplate restTemplate){
        this.productMapper = productMapper;
        this.restTemplate = restTemplate;
    }

    public Product getProductById(Integer id){
        return productMapper.selectByPrimaryKey(id);
    }

    public Order getOrder(Integer orderId){
        String url = "http://order-service/order/get/"+orderId;
        Order order = restTemplate.getForObject(url, Order.class);
        return order;
    }

}
